// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.scripting.objects;

import zombie.audio.GameSound;
import zombie.audio.GameSoundClip;
import zombie.core.math.PZMath;
import zombie.scripting.ScriptParser;

public final class GameSoundScript extends BaseScriptObject {
    public final GameSound gameSound = new GameSound();

    public void Load(String name, String totalFile) {
        this.gameSound.name = name;
        ScriptParser.Block block0 = ScriptParser.parse(totalFile);
        block0 = (ScriptParser.Block)block0.children.get(0);

        for (ScriptParser.Value value : block0.values) {
            String[] string0 = value.string.split("=");
            String string1 = string0[0].trim();
            String string2 = string0[1].trim();
            if ("category".equals(string1)) {
                this.gameSound.category = string2;
            } else if ("is3D".equals(string1)) {
                this.gameSound.is3D = Boolean.parseBoolean(string2);
            } else if ("loop".equals(string1)) {
                this.gameSound.loop = Boolean.parseBoolean(string2);
            } else if ("master".equals(string1)) {
                this.gameSound.master = GameSound.MasterVolume.valueOf(string2);
            } else if ("maxInstancesPerEmitter".equals(string1)) {
                this.gameSound.maxInstancesPerEmitter = PZMath.tryParseInt(string2, -1);
            }
        }

        for (ScriptParser.Block block1 : block0.children) {
            if ("clip".equals(block1.type)) {
                GameSoundClip gameSoundClip = this.LoadClip(block1);
                this.gameSound.clips.add(gameSoundClip);
            }
        }
    }

    private GameSoundClip LoadClip(ScriptParser.Block block) {
        GameSoundClip gameSoundClip = new GameSoundClip(this.gameSound);

        for (ScriptParser.Value value : block.values) {
            String[] string0 = value.string.split("=");
            String string1 = string0[0].trim();
            String string2 = string0[1].trim();
            if ("distanceMax".equals(string1)) {
                gameSoundClip.distanceMax = (float)Integer.parseInt(string2);
                gameSoundClip.initFlags = (short)(gameSoundClip.initFlags | GameSoundClip.INIT_FLAG_DISTANCE_MAX);
            } else if ("distanceMin".equals(string1)) {
                gameSoundClip.distanceMin = (float)Integer.parseInt(string2);
                gameSoundClip.initFlags = (short)(gameSoundClip.initFlags | GameSoundClip.INIT_FLAG_DISTANCE_MIN);
            } else if ("event".equals(string1)) {
                gameSoundClip.event = string2;
            } else if ("file".equals(string1)) {
                gameSoundClip.file = string2;
            } else if ("pitch".equals(string1)) {
                gameSoundClip.pitch = Float.parseFloat(string2);
            } else if ("volume".equals(string1)) {
                gameSoundClip.volume = Float.parseFloat(string2);
            } else if ("reverbFactor".equals(string1)) {
                gameSoundClip.reverbFactor = Float.parseFloat(string2);
            } else if ("reverbMaxRange".equals(string1)) {
                gameSoundClip.reverbMaxRange = Float.parseFloat(string2);
            }
        }

        return gameSoundClip;
    }

    public void reset() {
        this.gameSound.reset();
    }
}
